package com.lhnstart.learn.bases.string_;

/**
 * String 案例演示
 *
 * @author lhn
 * @date 2023/07/31 15:44
 * @since 1.0.0
 **/
public class String01 {

    public static void main(String[] args) {
        String name = "jack";

        String name2 = "jack";
        String name1 = new String("jack");
        String name3 = new String("jack");
        System.out.println(name1 == name);
        System.out.println(name2 == name);
        System.out.println(name1 == name3);
        System.out.println(System.identityHashCode(name));
        System.out.println(System.identityHashCode(name1));
        System.out.println(System.identityHashCode(name2));
        System.out.println(System.identityHashCode(name3));


        String s = new String("1");
        s.intern();
        String s2 = "1";
        System.out.println(s == s2);

        String s3 = new String("1") + new String("1");
        s3.intern();
        String s4 = "11";
        System.out.println(s3 == s4);

        System.out.println(System.identityHashCode(s3));
        System.out.println(System.identityHashCode(s4));

    }

}